<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/2/19
 * Time: 18:03
 */
namespace app\api\controller;
use think\Db;
class My extends Base {
    /**
     * 异地登录验证
     * @return string|void
     */
    public function _initialize()
    {
        header('Access-Control-Allow-Origin:*');
        extract(input());
        if($user_id != 0){
            $auth = $this->checkAll($user_id,$time,$value,$reqKey);
            if($auth == 112){
                echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
                exit;
            }elseif($auth == 110){
                echo json_encode(['status' => 302, 'msg' => $this->frost]);
                exit;
            }elseif($auth == 1103){
                echo json_encode(['status' => 303, 'msg' => $this->del]);
                exit;
            }
        }

    }
    /**
     * 我的收藏
     * @return \think\response\Json
     */
    public function myLikes(){
        extract(input());
        $where = [
            'like_user_id' => $user_id,
            'like_pp_id' => ['>',0]
        ];
        $field = 'pp_id,pp_name,pp_thumb';
        $field .= ',like_id,like_s_id,like_time';
        $data = Db::table('up_like l')
            ->join('up_pp pp','l.like_pp_id = pp.pp_id','left')
            ->where($where)
            ->order('like_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的收藏案例
     * @return \think\response\Json
     */
    public function myCaseLikes(){
        extract(input());
        $can = Db::table('up_about')->where('id',21)->value('content');
        if($can == 2) return json(['status' => 200,'msg' => []]);
        $where = [
            'like_user_id' => $user_id,
            'like_case_id' => ['>',0]
        ];
        $field = 'case_id,case_name,case_size,room_name,style_name';
        $field .= ',like_id,like_time';
        $data = Db::table('up_like_case l')
            ->join('up_case c','l.like_case_id = c.case_id','left')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->where($where)
            ->order('like_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的收藏设计师
     * @return \think\response\Json
     */
    public function myUsersLikes(){
        extract(input());
        $can = Db::table('up_about')->where('id',18)->value('content');
        if($can == 2) return json(['status' => 200,'msg' => []]);
        $where = [
            'like_user_id' => $user_id,
            'like_other_id' => ['>',0]
        ];
        $field = 'user_id,user_d_name,user_image';
        $field .= ',like_id,like_time';
        $data = Db::table('up_like_user l')
            ->join('up_u_user u','l.like_other_id = u.user_id','left')
            ->where($where)
            ->order('like_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的案例浏览记录
     * @return \think\response\Json
     */
    public function myCaseHistory(){
        extract(input());
        $can = Db::table('up_about')->where('id',21)->value('content');
        if($can == 2) return json(['status' => 200,'msg' => []]);
        $where = [
            'h_user_id' => $user_id,
            'case_id' => ['>',0]
        ];
        $field = 'case_id,case_name,case_size,room_name,style_name';
        $field .= ',h_id,h_time';
        $data = Db::table('up_history_case his')
            ->join('up_case c','his.h_case_id = c.case_id','left')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->where($where)
            ->order('h_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的浏览记录
     * @return \think\response\Json
     */
    public function myHistory(){
        extract(input());
        $where = [
            'h_user_id' => $user_id,
            'pp_id' => ['>',0]
        ];
        $field = 'pp_id,pp_name,pp_thumb';
        $field .= ',h_id,h_s_id,h_time';
        $data = Db::table('up_history his')
            ->join('up_pp pp','his.h_pp_id = pp.pp_id','left')
            ->where($where)
            ->order('h_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的浏览记录设计师
     * @return \think\response\Json
     */
    public function myUsersHistory(){
        extract(input());
        $can = Db::table('up_about')->where('id',18)->value('content');
        if($can == 2) return json(['status' => 200,'msg' => []]);
        $where = [
            'h_user_id' => $user_id,
            'h_other_id' => ['>',0]
        ];
        $field = 'user_id,user_d_name,user_image';
        $field .= ',h_id,h_time';
        $data = Db::table('up_history_user his')
            ->join('up_u_user u','his.h_other_id = u.user_id','left')
            ->where($where)
            ->order('h_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的浏览记录商品
     * @return \think\response\Json
     */
    public function myGoodsHistory(){
        extract(input());
        $where = [
            'h_user_id' => $user_id,
            'good_id' => ['>',0]
        ];
        $field = 'good_id,good_name,good_thumb';
        $field .= ',h_id,h_time';
        $data = Db::table('up_history_goods his')
            ->join('up_store_goods g','his.h_good_id = g.good_id','left')
            ->where($where)
            ->order('h_time desc')
            ->page($page,20)
            ->field($field)
            ->select();
        return json(array('status'=>200,'msg'=>$data));
    }
    /**
     * 我的账单
     * @return \think\response\Json
     */
    public function myCheck(){
        extract(input());
        $where = [
            'ud_user_id' => $user_id
        ];
        $moneys = Db::table('up_user_date')
            ->where($where)
            ->sum('ud_money');
        $saves = Db::table('up_user_date')
            ->where($where)
            ->sum('ud_money_save');
        $data = Db::table('up_user_date')
            ->where($where)
            ->order('ud_date desc')
            ->page($page,20)
            ->select();
        return json(array('status'=>200,'msg'=>$data,'moneys'=>sprintf("%.2f",$moneys),'saves'=>sprintf("%.2f",$saves)));
    }
    /**
     * 我的账单——新增
     * @return \think\response\Json
     */
    public function myCheckAdd(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        if(!isset($ud_type) || !$ud_type){
            $ud_type = 1;
        }
        if($ud_type == 1){
            $ud_type_name = Db::table('up_types')->where('t_id',$ud_t_id)->value('t_name');
            $ud_pp_name = Db::table('up_pp')->where('pp_id',$ud_pp_id)->value('pp_name');
        }else{
            $ud_t_id = 0;
            $ud_pp_id = 0;
            $ud_type_name = $type_name;
            $ud_pp_name = $pp_name;
        }

        $insert = [
            'ud_user_id' => $user_id,
            'ud_date' => $ud_date,
            'ud_money' => $ud_money,
            'ud_type' => $ud_type,
            'ud_t_id' => $ud_t_id,
            'ud_type_name' => $ud_type_name,
            'ud_pp_id' => $ud_pp_id,
            'ud_pp_name' => $ud_pp_name,
            'ud_remark' => $ud_remark,
            'ud_time' => $today,
            'ud_update' => $today,
        ];
        $res = Db::table('up_user_date')
            ->insert($insert);
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    /**
     * 我的账单——详情
     * @return \think\response\Json
     */
    public function myCheckInfo(){
        extract(input());
        $data = Db::table('up_user_date')->where('ud_id',$ud_id)->find();
        return json(['status'=>200,'msg'=>$data]);
    }
    /**
     * 我的账单——编辑
     * @return \think\response\Json
     */
    public function myCheckUpdate(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        if(!isset($ud_type) || !$ud_type){
            $ud_type = 1;
        }
        if($ud_type == 1){
            $ud_type_name = Db::table('up_types')->where('t_id',$ud_t_id)->value('t_name');
            $ud_pp_name = Db::table('up_pp')->where('pp_id',$ud_pp_id)->value('pp_name');
        }else{
            $ud_t_id = 0;
            $ud_pp_id = 0;
            $ud_type_name = $type_name;
            $ud_pp_name = $pp_name;
        }
        $update = [
            'ud_date' => $ud_date,
            'ud_money' => $ud_money,
            'ud_type' => $ud_type,
            'ud_t_id' => $ud_t_id,
            'ud_type_name' => $ud_type_name,
            'ud_pp_id' => $ud_pp_id,
            'ud_pp_name' => $ud_pp_name,
            'ud_remark' => $ud_remark,
            'ud_update' => $today,
        ];
        $res = Db::table('up_user_date')->where('ud_id',$ud_id)->update($update);
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    /**
     * 我的账单——删除
     * @return \think\response\Json
     */
    public function myCheckDel(){
        extract(input());
        $res = Db::table('up_user_date')->where('ud_id',$ud_id)->delete();
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>100,'msg'=>'操作失败，请刷新重试！']);
        }
    }
    //-------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------
    /**
     * 常见问题
     * @return \think\response\Json
     */
    public function questions(){
        extract(input());
        $list = Db::table('up_question')
            ->where('q_status',1)
            ->field('q_content',true)
            ->page($page,20)
            ->order('q_time desc')
            ->select();
        return json(['status'=>200,'msg'=>$list]);

    }
    /**
     * 常见问题详情
     * @return \think\response\Json
     */
    public function questionInfo(){
        extract(input());
        $where['q_id'] = $q_id;
        $data = Db::table('up_question')
            ->where($where)
            ->find();
        return json(['status'=>200,'msg'=>$data]);

    }
    public function feedback(){
            extract(input());
        $data = [
            'f_user_id' => $user_id,
            'feedback_content' => $content,
            'feedback_phone' => $phone,
            'feedback_time' => date('Y-m-d H:i:s'),
        ];
        $res = Db::table('up_feedback')->insert($data);
        if($res){
            return json(array('status'=>200,'msg'=>"成功"));
        }else{
            return json(array('status'=>0,'msg'=>"失败"));
        }
    }
    /**
     * 视频评论数据
     * @return string
     */
    public function myComments()
    {
        extract(input());
        $where = [
            'vc_user_id' => $user_id,
        ];
        $data = Db::table('up_video_comment')->alias('vc')
            ->join('up_pp_video v','vc.vc_v_id=v.v_id','LEFT')
            ->where($where)
            ->order('vc_time desc')
            ->field("vc.*,v_url,v_title,v_id")
            ->page($page,10)
            ->select();
        foreach ($data as $k => $v){
            $data[$k]['v_thumb'] = $v['v_url'] . '?vframe/jpg/offset/1';
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 视频评论数据
     * @return string
     */
    public function myReplys()
    {
        extract(input());
        $where = [
            'vc_user_id|vcr_user_id' => $user_id,
        ];
        $data = Db::table('up_video_comment_reply')->alias('vcr')
            ->join('up_video_comment vc','vcr.vcr_vc_id=vc.vc_id','LEFT')
            ->join('up_pp_video v','vc.vc_v_id=v.v_id','LEFT')
            ->join('up_u_user u','vc.vc_user_id=u.user_id','LEFT')
            ->where($where)
            ->order('vcr_time desc')
            ->field("vcr.*,vc_content,vc_time,user_id,user_username,user_image,v_url,v_title,v_id")
            ->page($page,10)
            ->select();
        foreach ($data as $k => $v){
            $data[$k]['v_thumb'] = $v['v_url'] . '?vframe/jpg/offset/1';
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 所有的视频评论数据
     * @return string
     */
    public function myAlls()
    {
        extract(input());
        $page = ($page - 1) * 20;
        $data = DB::query("SELECT
            *
        FROM
            (
                (
                    SELECT
                        vc_content,
                        vc_time,
                        1 AS del_type,
                        vc_user_id AS my_uid,
                        vc_id AS del_id,
                        user_username,user_image,v_url,v_pp_id,v_s_id,v_title,v_nums,v_type,v_id AS id
                  
                    FROM
                        up_video_comment vc
                    LEFT JOIN up_u_user u ON vc.vc_user_id = u.user_id
                    LEFT JOIN up_pp_video v ON vc.vc_v_id = v.v_id
                    WHERE
                        vc.vc_user_id ={$user_id}
                )
                UNION ALL
                (
                    SELECT
                        vcr_content AS vc_content,
                        vcr_time AS vc_time,
                        2 AS del_type,
                        vcr_user_id AS my_uid,
                        vcr_id AS del_id,
                        user_username,user_image,v_url,v_pp_id,v_s_id,v_title,v_nums,v_type,v_id AS id
                    FROM
                        up_video_comment_reply vcr
                    LEFT JOIN up_u_user u ON vcr.vcr_user_id = u.user_id
                    LEFT JOIN up_video_comment vc ON vcr.vcr_vc_id = vc.vc_id
                    LEFT JOIN up_pp_video v ON vc.vc_v_id = v.v_id
                    WHERE
                        vcr.vcr_user_id ={$user_id}
                    OR vc.vc_user_id ={$user_id}
                )                
            ) AS L
        ORDER BY
            L.vc_time DESC
        LIMIT {$page},
         20");
        foreach ($data as $k => $v){
            if($v['v_type'] == 1){
                $pp = Db::table('up_pp')
                    ->where('pp_id',$v['v_pp_id'])
                    ->field('pp_id,pp_name,pp_thumb')
                    ->find();
                $data[$k]['pp_id'] = $pp['pp_id'];
                $data[$k]['pp_name'] = $pp['pp_name'];
                $data[$k]['pp_thumb'] = $pp['pp_thumb'];
            }else{
                $pp = Db::table('up_u_user')
                    ->where('user_id',$v['v_pp_id'])
                    ->field('user_d_name,user_image')
                    ->find();
                $data[$k]['user_d_name'] = $pp['user_d_name'];
                $data[$k]['user_d_image'] = $pp['user_image'];
            }
            $data[$k]['v_thumb'] = $v['v_url'] . '?vframe/jpg/offset/1';
            $data[$k]['zan'] = 0;
            $have = Db::table('up_zan')
                ->where('zan_v_id',$v['id'])
                ->where('zan_user_id',$user_id)
                ->find();
            if($have) $data[$k]['zan'] = 1;
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 删除评论
     * @return string
     */
    public function delComm()
    {
        extract(input());
        if($del_type == 1){
            Db::table('up_video_comment')->where('vc_id',$del_id)->delete();
            Db::table('up_video_comment_reply')->where('vcr_v_id',$del_id)->delete();
        }else{
            Db::table('up_video_comment_reply')->where('vcr_id',$del_id)->delete();
        }
        return json(['status' => 200,'msg' => '删除成功']);
    }
    /**
     * 我的赞
     * @return string
     */
    public function myZans()
    {
        extract(input());
        $where = [
            'zan_user_id' => $user_id,
            'v_id' => ['>',0],
        ];
        $data = Db::table('up_zan')->alias('z')
            ->join('up_pp_video v','z.zan_v_id=v.v_id','LEFT')
            ->join('up_pp pp','v.v_pp_id=pp.pp_id','LEFT')
            ->join('up_u_user u','v.v_pp_id=u.user_id','LEFT')
            ->where($where)
            ->order('zan_time desc')
            ->field("z.*,v_id id,v_url,v_pp_id,v_s_id,v_title,v_nums,v_type,pp_id,pp_name,pp_thumb,user_d_name user_username,user_image")
            ->page($page,21)
            ->select();
        foreach ($data as $k => $v){
            $data[$k]['v_thumb'] = $v['v_url'] . '?vframe/jpg/offset/1';
            $data[$k]['zan'] = 0;
            $have = Db::table('up_zan')
                ->where('zan_v_id',$v['id'])
                ->where('zan_user_id',$user_id)
                ->find();
            if($have) $data[$k]['zan'] = 1;
        }
        return json(['status' => 200,'msg' => $data]);
    }
    /**
     * 我的商品收藏
     * @return string
     */
    public function myGoods()
    {
        extract(input());
        $where = [
            'like_user_id' => $user_id,
            'good_id' => ['>',0],
        ];
        if(isset($keyword) && $keyword) $where['good_name'] = ['like','%'.$keyword.'%'];
        $data = Db::table('up_like_good')->alias('like')
            ->join('up_store_goods g','like.like_good_id=g.good_id','LEFT')
            ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
            ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
            ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
            ->join('up_store s','g.good_s_id=s.s_id','LEFT')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->where($where)
            ->order('like_time desc')
            ->field("like_time,g.*,pp_name,st_name,spp_name,sstyle_name")
            ->page($page,10)
            ->select();
        $datasNums = Db::table('up_like_good')->alias('like')
            ->join('up_store_goods g','like.like_good_id=g.good_id','LEFT')
            ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
            ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
            ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
            ->join('up_store s','g.good_s_id=s.s_id','LEFT')
            ->join('up_pp pp','s.s_pp_id=pp.pp_id','LEFT')
            ->join('up_types t','pp.pp_t_id=t.t_id','LEFT')
            ->where($where)
            ->count();
        return json(['status' => 200,'msg' => $data,'good_nums'=>'共计 ' . $datasNums . ' 件']);
    }
    /**
     * 客户案例收藏
     * @return \think\response\Json
     */
//    public function caseShopLikes()
//    {
//        extract(input());
//        $where = [
//            'like_user_id' => $user_id,
//            'case_status' => 1,
//            'case_id' => ['>',0]
//        ];
//        $userInfo = Db::table('up_u_user')
//            ->where('user_id',$user_id)
//            ->field('user_type,user_my,user_see_cases,user_case_jindus,user_works')
//            ->find();
//        if($userInfo['user_works']) $where['like_user_id'] = ['in',$userInfo['user_works'] . ',' . $user_id];
//        //能看到的案例和类型
//        if(!$userInfo['user_see_cases'] || !$userInfo['user_case_jindus']) return json(['status'=>200,'data'=>[],'case_nums'=>'共有' . 0 . '个']);
//        if($userInfo['user_see_cases'] != -1) $where['case_id'] = ['in',$userInfo['user_see_cases']];
//        if($userInfo['user_case_jindus'] != -1) $where['case_jindu'] = ['in',$userInfo['user_case_jindus']];
//        if(isset($keyword) && $keyword){ // 空间
//            $where['case_name'] = ['like','%'.$keyword.'%'];
//        }
////        if(isset($qu_id) && $qu_id){ // 区域
////            $where['case_qu'] = $qu_id;
////        }
//        if(isset($qu) && $qu){ // 区域
//            $where['case_qu'] = $qu;
//        }
//        if(isset($style_id) && $style_id){ // 风格
//            $where['case_style'] = $style_id;
//        }
//        if(isset($size_id) && $size_id){ // 面积
//            $sizeData = Db::table('up_size')->where('size_id',$size_id)->find();
//            $where['case_size'] = ['between',"{$sizeData['size_min']},{$sizeData['size_max']}"];
//        }
//        $order1 = 'like_time desc';
//
//        if(isset($order) && $order){ // 区域
//            if($order == 1){
//                $order1 = 'like_time desc';
//            }
//            if($order == 2){
//                $order1 = 'like_jilu_time desc';
//            }
//            if($order == 3){
//                $order1 = 'case_letter asc,case_sort desc';
//            }
//            if($order == 4){
//                $order1 = 'distance asc,case_sort desc';
//            }
//            if($order == 5){
//                $order1 = 'case_size desc,case_sort desc';
//            }
//            if($order == 6){
//                $order1 = 'case_size asc,case_sort desc';
//            }
//            if($order == 7){
//                $order1 = 'case_shejishi_letter asc,case_sort desc';
//            }
//            if($order == 8){
//                $order1 = 'case_company_letter asc,case_sort desc';
//            }
//        }
//        if(isset($shaixuan) && $shaixuan){ // 筛选
//            if($shaixuan == 1){
//                $where['case_shejishi_have'] = 2;
//            }
//            if($shaixuan == 2){
//                $where['case_shejishi_have'] = 1;
//            }
//            if($shaixuan == 3){
//                $where['case_bianhua'] = 2;
//            }
//        }
//        if(isset($jindu) && $jindu) {
//            $where['case_jindu'] = $jindu;
//        }
//
//        //-----------------------pp_id start -----------------------
//        $data = Db::table('up_like_case')->alias('l')
//            ->join('up_case c','l.like_case_id=c.case_id','LEFT')
//            ->join('up_room r','c.case_room=r.room_id','LEFT')
//            ->join('up_style s','c.case_style=s.style_id','LEFT')
//            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
//            ->where($where)
//            ->order($order1)
//            ->field("l.*,c.*,room_name,jindu_name,style_name,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - case_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(case_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - case_lon * PI() / 180) / 2),2))) * 1000) AS distance")
//            ->page($page,10)
//            ->select();
//        if($data){
//            foreach ($data as $k => $v){
//                $data[$k]['jilu'] = [];
//                $jilu = Db::table('up_like_case_shop_jilu')
//                    ->where('jilu_user_id',$user_id)
//                    ->where('jilu_case_id',$v['case_id'])
//                    ->order('jilu_time desc')
//                    ->find();
//                if($jilu) $data[$k]['jilu'] = $jilu;
//            }
//        }
//        //------------------------数量--------------------------------------------------------
//        $nums = Db::table('up_like_case')->alias('l')
//            ->join('up_case c','l.like_case_id=c.case_id','LEFT')
//            ->join('up_room r','c.case_room=r.room_id','LEFT')
//            ->join('up_style s','c.case_style=s.style_id','LEFT')
//            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
//            ->where($where)
//            ->count();
//        return json(['status'=>200,'data'=>$data,'case_nums'=>'共收藏' . $nums . '个客户']);
//    }
    /**
     * 客户案例收藏
     * @return \think\response\Json
     */
    public function caseShopLikes()
    {
        extract(input());
        $where = [
            'like_user_id' => $user_id,
            'case_status' => 1,
            'case_id' => ['>',0]
        ];
        $userInfo = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_type,user_my,user_see_cases,user_case_jindus')
            ->find();
        if(!$userInfo['user_see_cases'] || !$userInfo['user_case_jindus']) return json(['status'=>200,'data'=>[],'case_nums'=>'共有' . 0 . '个']);
        if($userInfo['user_see_cases'] != -1) $where['case_id'] = ['in',$userInfo['user_see_cases']];
        if(isset($keyword) && $keyword){ // 空间
            $where['case_name'] = ['like','%'.$keyword.'%'];
        }
        if(isset($qu_id) && $qu_id){ // 区域
            $where['case_qu'] = $qu_id;
        }
        $order1 = 'like_time desc';

        if(isset($order) && $order){ // 区域
            if($order == 1){
                $order1 = 'like_time desc';
            }
            if($order == 2){
                $order1 = 'like_jilu_time desc';
            }
            if($order == 3){
                $order1 = 'case_letter asc,case_sort desc';
            }
            if($order == 4){
                $order1 = 'distance asc,case_sort desc';
            }
            if($order == 5){
                $order1 = 'case_size desc,case_sort desc';
            }
            if($order == 6){
                $order1 = 'case_size asc,case_sort desc';
            }
            if($order == 7){
                $order1 = 'like_jilu_time asc';
            }
        }

        //-----------------------pp_id start -----------------------
        if(isset($jindu) && $jindu) {
            $where['case_jindu'] = $jindu;
        }
        $data = Db::table('up_like_case')->alias('l')
            ->join('up_case c','l.like_case_id=c.case_id','LEFT')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
            ->where($where)
            ->order($order1)
            ->field("l.*,c.*,jindu_name,room_name,style_name,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat* PI() / 180 - case_lat * PI() / 180) / 2),2) + COS($lat * PI() / 180) * COS(case_lat * PI() / 180) * POW(SIN(($lon * PI() / 180 - case_lon * PI() / 180) / 2),2))) * 1000) AS distance")
            ->page($page,10)
            ->select();
        if($data){
            foreach ($data as $k => $v){
                $data[$k]['jilu'] = [];
                $jilu = Db::table('up_like_case_shop_jilu')
                    ->where('jilu_user_id',$user_id)
                    ->where('jilu_case_id',$v['case_id'])
                    ->order('jilu_time desc')
                    ->find();
                if($jilu) $data[$k]['jilu'] = $jilu;
            }
        }
        //------------------------数量--------------------------------------------------------
        $nums = Db::table('up_like_case')->alias('l')
            ->join('up_case c','l.like_case_id=c.case_id','LEFT')
            ->join('up_room r','c.case_room=r.room_id','LEFT')
            ->join('up_style s','c.case_style=s.style_id','LEFT')
            ->join('up_jindu j','c.case_jindu=j.jindu_id','LEFT')
            ->where($where)
            ->count();
        return json(['status'=>200,'data'=>$data,'case_nums'=>'共收藏' . $nums . '个客户']);
    }
    public function getJilu(){
        extract(input());
        $jilu = Db::table('up_like_case_shop_jilu')
            ->where('jilu_user_id',$user_id)
            ->where('jilu_case_id',$case_id)
            ->order('jilu_time desc')
            ->select();
        return json(['status'=>200,'msg'=>$jilu]);
    }
    public function getJiluInfo(){
        extract(input());
        $jilu = Db::table('up_like_case_shop_jilu')
            ->where('jilu_id',$jilu_id)
            ->find();
        return json(['status'=>200,'msg'=>$jilu]);
    }
    public function addJilu(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        $data = [
            'jilu_user_id' => $user_id,
            'jilu_case_id' => $case_id,
            'jilu_content' => $jilu_content,
            'jilu_time' => $today
        ];
        $res = Db::table('up_like_case_shop_jilu')->insert($data);
        if($res) {
            Db::table('up_like_case')
                ->where('like_user_id',$user_id)
                ->where('like_case_id',$case_id)
                ->setField('like_jilu_time',$today);
            return json(['status'=>200,'msg'=>'记录成功']);
        }
        return json(['status'=>100,'msg'=>'记录失败，请重试']);
    }
    public function editJilu(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        $data = [
            'jilu_content' => $jilu_content,
            'jilu_time' => $today
        ];
        $res = Db::table('up_like_case_shop_jilu')->where('jilu_id',$jilu_id)->update($data);
        if($res) {
            $case = Db::table('up_like_case_shop_jilu')->where('jilu_id',$jilu_id)->find();
            Db::table('up_like_case')
                ->where('like_user_id',$case['jilu_user_id'])
                ->where('like_case_id',$case['jilu_case_id'])
                ->setField('like_jilu_time',$today);
            return json(['status'=>200,'msg'=>'记录成功']);
        }
        return json(['status'=>100,'msg'=>'记录失败，请重试']);
    }
    public function delJilu(){
        extract(input());
        $res = Db::table('up_like_case_shop_jilu')->where('jilu_id',$jilu_id)->delete();
        if($res) {
            return json(['status'=>200,'msg'=>'记录成功']);
        }
        return json(['status'=>100,'msg'=>'记录失败，请重试']);
    }
    //-----------------------------------------------------------------------------------------------------
    public function getMyCases(){
        extract(input());
        $jilu = Db::table('up_case_copy')
            ->where('case_user_id',$user_id)
            ->where('case_verify','<>',4)
            ->order('case_time desc')
            ->page($page,10)
            ->select();
        return json(['status'=>200,'msg'=>$jilu]);
    }
    public function getMyCaseInfo(){
        extract(input());
        $jilu = Db::table('up_case_copy')
            ->where('case_id',$case_id)
            ->find();
        return json(['status'=>200,'msg'=>$jilu]);
    }
    public function addMyCase(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        $flag = false;
        if($case_phone) {
            if(!preg_match("/^1[123456789]\d{9}$/", $case_phone)) return json(['status'=>100,'msg'=>'手机号错误~']);
            $flag = true;
            $have1 = Db::table('up_case')
                ->where('case_phone|case_phone2|case_phone3|case_phone4|case_phone5',$case_phone)
                ->find();
            $have2 = Db::table('up_case_copy')
                ->where('case_phone|case_phone2',$case_phone)
                ->where('case_verify','in','1,2')
                ->find();
            if($have1 || $have2) return json(['status'=>100,'msg'=>'已经有此手机号的客户~']);
        }
        if($case_phone2) {
            if(!preg_match("/^1[123456789]\d{9}$/", $case_phone2)) return json(['status'=>100,'msg'=>'手机号错误~']);
            $flag = true;
            $have1 = Db::table('up_case')
                ->where('case_phone|case_phone2|case_phone3|case_phone4|case_phone5',$case_phone2)
                ->find();
            $have2 = Db::table('up_case_copy')
                ->where('case_phone|case_phone2',$case_phone2)
                ->where('case_verify','in','1,2')
                ->find();
            if($have1 || $have2) return json(['status'=>100,'msg'=>'已经有此手机号的客户~']);
        }
        if(isset($heshi) && $heshi == 1) return json(['status'=>200,'msg'=>'恭喜您，无此手机号客户~']);
        $data = [
            'case_name' => $case_name,
            'case_address' => $case_address,
            'case_phone' => $case_phone,
            'case_phone2' => $case_phone2,
            'case_username' => $case_username,
            'case_username2' => $case_username2,
            'case_info' => $case_info,
            'case_user_id' => $user_id,
            'case_who' => $user_id,
            'case_verify' => 1,
            'case_time' => $today
        ];
        if($flag == false) return json(['status'=>100,'msg'=>'请至少填写一个客户信息~']);
        $res = Db::table('up_case_copy')->insert($data);
        if($res) return json(['status'=>200,'msg'=>'新建成功，请耐心等待审核~']);
        return json(['status'=>100,'msg'=>'添加失败，请重试']);
    }
    public function editMyCase(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        $flag = false;
        if($case_phone) {
            if(!preg_match("/^1[123456789]\d{9}$/", $case_phone)) return json(['status'=>100,'msg'=>'手机号错误~']);
            $flag = true;
            $have1 = Db::table('up_case')
                ->where('case_phone|case_phone2|case_phone3|case_phone4|case_phone5',$case_phone)
                ->find();
            $have2 = Db::table('up_case_copy')
                ->where('case_phone|case_phone2',$case_phone)
                ->where('case_verify','in','1,2')
                ->find();
            if($have1 || $have2) return json(['status'=>100,'msg'=>'已经有此手机号的客户~']);
        }
        if($case_phone2) {
            if(!preg_match("/^1[123456789]\d{9}$/", $case_phone2)) return json(['status'=>100,'msg'=>'手机号错误~']);
            $flag = true;
            $have1 = Db::table('up_case')
                ->where('case_phone|case_phone2|case_phone3|case_phone4|case_phone5',$case_phone2)
                ->find();
            $have2 = Db::table('up_case_copy')
                ->where('case_phone|case_phone2',$case_phone2)
                ->where('case_verify','in','1,2')
                ->find();
            if($have1 || $have2) return json(['status'=>100,'msg'=>'已经有此手机号的客户~']);
        }
        if(isset($heshi) && $heshi == 1) return json(['status'=>200,'msg'=>'恭喜您，无此手机号客户~']);
        $case = Db::table('up_case_copy')->where('case_id',$case_id)->find();
        if($case['case_verify'] != 3) return json(['status'=>100,'msg'=>'只要被拒绝的才可以编辑~']);
        $data = [
            'case_name' => $case_name,
            'case_address' => $case_address,
            'case_phone' => $case_phone,
            'case_phone2' => $case_phone2,
            'case_username' => $case_username,
            'case_username2' => $case_username2,
            'case_info' => $case_info,
            'case_user_id' => $user_id,
            'case_who' => $user_id,
            'case_verify' => 1,
            'case_time' => $today
        ];
        if($flag == false) return json(['status'=>100,'msg'=>'请至少填写一个客户信息~']);
        $res = Db::table('up_case_copy')->where('case_id',$case_id)->update($data);
        if($res) return json(['status'=>200,'msg'=>'提交成功，请耐心等待审核~']);
        return json(['status'=>100,'msg'=>'提交失败，请重试']);
    }
    public function delMyCase(){
        extract(input());
        $res = Db::table('up_case_copy')
            ->where('case_id',$case_id)
            ->setField('case_verify',4);
        if($res) {
            return json(['status'=>200,'msg'=>'删除成功']);
        }
        return json(['status'=>100,'msg'=>'删除失败，请重试']);
    }
    //---分配我收藏的案例----------------

}